//
//  UIBarButtonItem+Extension.swift
//  传智微博
//
//  Created by zuxi li on 2017/3/15.
//  Copyright © 2017年 lingtu. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认16号
    ///   - target: target
    ///   - action: action
    ///   - isBackButton: 是否是返回按钮，如果是加上箭头
    /// - returns: UIBarButtronItem
    convenience init(title: String, fontSize:CGFloat = 16, target: AnyObject?, action: Selector, isBackButton: Bool = false) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBackButton {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName+"_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //self.init 实例化 UIbarButtonItem
        self.init(customView:btn)
    }
}




















